# -*- coding: utf-8 -*-

# Form implementation for modern UI layout
# This is a completely redesigned UI with top navigation and card-based layout

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainGUI(object):
    def setupUi(self, MainGUI):
        MainGUI.setObjectName("MainGUI")
        MainGUI.resize(1400, 1400)
        MainGUI.setMinimumSize(QtCore.QSize(1200, 1000))
        
        # Main layout
        self.centralWidget = QtWidgets.QWidget(MainGUI)
        self.centralWidget.setObjectName("centralWidget")
        
        # Vertical layout for the entire window
        self.mainVerticalLayout = QtWidgets.QVBoxLayout(self.centralWidget)
        self.mainVerticalLayout.setContentsMargins(0, 0, 0, 0)
        self.mainVerticalLayout.setSpacing(0)
        self.mainVerticalLayout.setObjectName("mainVerticalLayout")
        
        # Top header frame
        self.headerFrame = QtWidgets.QFrame(self.centralWidget)
        self.headerFrame.setFixedHeight(100)
        self.headerFrame.setStyleSheet("""
            QFrame {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #667eea, stop: 1 #764ba2);
                border: none;
                border-bottom: 3px solid rgba(255, 255, 255, 0.3);
            }
        """)
        self.headerFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.headerFrame.setObjectName("headerFrame")
        
        # Header layout
        self.headerLayout = QtWidgets.QHBoxLayout(self.headerFrame)
        self.headerLayout.setContentsMargins(40, 15, 40, 15)
        self.headerLayout.setSpacing(30)
        self.headerLayout.setObjectName("headerLayout")
        
        # App title
        self.appTitle = QtWidgets.QLabel(self.headerFrame)
        self.appTitle.setStyleSheet("""
            QLabel {
                color: white;
                font-size: 32px;
                font-weight: bold;
                background: transparent;
                text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
            }
        """)
        self.appTitle.setText("By_Ti")
        self.appTitle.setObjectName("appTitle")
        self.headerLayout.addWidget(self.appTitle)
        
        # Spacer
        spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.headerLayout.addItem(spacer)
        
        # User info card in header
        self.userInfoCard = QtWidgets.QFrame(self.headerFrame)
        self.userInfoCard.setFixedSize(280, 70)
        self.userInfoCard.setStyleSheet("""
            QFrame {
                background-color: rgba(255, 255, 255, 0.25);
                border-radius: 15px;
                border: none;
                backdrop-filter: blur(10px);
            }
        """)
        self.userInfoCard.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.userInfoCard.setObjectName("userInfoCard")
        
        # User info layout
        self.userInfoLayout = QtWidgets.QHBoxLayout(self.userInfoCard)
        self.userInfoLayout.setContentsMargins(15, 10, 15, 10)
        self.userInfoLayout.setSpacing(15)
        self.userInfoLayout.setObjectName("userInfoLayout")
        
        # User avatar
        self.userImg_label = QtWidgets.QLabel(self.userInfoCard)
        self.userImg_label.setFixedSize(60, 60)
        self.userImg_label.setStyleSheet("""
            QLabel {
                background-color: rgba(255, 255, 255, 0.4);
                border-radius: 30px;
                border: none;
                box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            }
        """)
        self.userImg_label.setText("")
        self.userImg_label.setAlignment(QtCore.Qt.AlignCenter)
        self.userImg_label.setObjectName("userImg_label")
        self.userInfoLayout.addWidget(self.userImg_label)
        
        # User name
        self.username_label = QtWidgets.QLabel(self.userInfoCard)
        self.username_label.setStyleSheet("""
            QLabel {
                color: white;
                font-size: 16px;
                font-weight: bold;
                background: transparent;
                text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
            }
        """)
        self.username_label.setText("未登录")
        self.username_label.setAlignment(QtCore.Qt.AlignCenter)
        self.username_label.setObjectName("username_label")
        self.userInfoLayout.addWidget(self.username_label)
        
        self.headerLayout.addWidget(self.userInfoCard)
        self.mainVerticalLayout.addWidget(self.headerFrame)
        
        # Navigation tabs
        self.navTabWidget = QtWidgets.QTabWidget(self.centralWidget)
        self.navTabWidget.setStyleSheet("""
            QTabWidget::pane {
                border: none;
                background-color: #f8f9fa;
                margin-top: 5px;
            }
            QTabBar::tab {
                background: #e9ecef;
                color: #495057;
                padding: 16px 32px;
                margin-right: 4px;
                border-top-left-radius: 12px;
                border-top-right-radius: 12px;
                font-size: 16px;
                font-weight: 600;
                min-width: 120px;
                border: 2px solid transparent;
            }
            QTabBar::tab:selected {
                background: white;
                color: #667eea;
                border-bottom: 4px solid #667eea;
                border-top: 2px solid #667eea;
                border-left: 2px solid #667eea;
                border-right: 2px solid #667eea;
                margin-bottom: -2px;
            }
            QTabBar::tab:hover {
                background: #dee2e6;
                color: #495057;
            }
        """)
        self.navTabWidget.setObjectName("navTabWidget")
        
        # Task Tab
        self.taskTab = QtWidgets.QWidget()
        self.taskTab.setObjectName("taskTab")
        self.setupTaskTab()
        self.navTabWidget.addTab(self.taskTab, "创建任务")
        
        # Progress Tab
        self.progressTab = QtWidgets.QWidget()
        self.progressTab.setObjectName("progressTab")
        self.setupProgressTab()
        self.navTabWidget.addTab(self.progressTab, "任务进度")
        
        # Settings Tab
        self.settingsTab = QtWidgets.QWidget()
        self.settingsTab.setObjectName("settingsTab")
        self.setupSettingsTab()
        self.navTabWidget.addTab(self.settingsTab, "设置")
        
        self.mainVerticalLayout.addWidget(self.navTabWidget)
        
        # Set the central widget
        MainGUI.setLayout(self.mainVerticalLayout)
        
        # Connect tab change signal to method
        self.navTabWidget.currentChanged.connect(self.onTabChanged)
        
        # Set initial tab
        self.navTabWidget.setCurrentIndex(0)
        
        # Create compatibility properties for existing code
        self.setupCompatibilityProperties()
        
        # Setup responsive design
        self.setupResponsiveDesign(MainGUI)
        
        self.retranslateUi(MainGUI)
        QtCore.QMetaObject.connectSlotsByName(MainGUI)




    def setupTaskTab(self):
        """设置任务创建标签页"""
        layout = QtWidgets.QVBoxLayout(self.taskTab)
        layout.setContentsMargins(80, 60, 80, 60)
        layout.setSpacing(30)
        
        # Task creation card
        self.taskCard = QtWidgets.QFrame()
        self.taskCard.setStyleSheet("""
            QFrame {
                background-color: white;
                border-radius: 20px;
                border: 1px solid #e0e0e0;
                box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            }
        """)
        
        self.taskCardLayout = QtWidgets.QVBoxLayout(self.taskCard)
        self.taskCardLayout.setContentsMargins(60, 50, 60, 50)
        self.taskCardLayout.setSpacing(40)
        
        # Title
        self.taskTitle = QtWidgets.QLabel("创建学习任务")
        self.taskTitle.setStyleSheet("""
            QLabel {
                font-size: 32px;
                font-weight: bold;
                color: #333;
                margin-bottom: 15px;
                border: none;
                background: transparent;
            }
        """)
        self.taskCardLayout.addWidget(self.taskTitle)
        
        # Form grid
        self.formGrid = QtWidgets.QGridLayout()
        self.formGrid.setSpacing(30)
        self.formGrid.setColumnMinimumWidth(0, 180)  # 设置标签列最小宽度
        self.formGrid.setColumnStretch(1, 1)  # 输入框列可拉伸
        
        # Course type
        self.courseTypeLabel = QtWidgets.QLabel("课程类型")
        self.courseTypeLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.courseType_comboBox = QtWidgets.QComboBox()
        self.courseType_comboBox.setStyleSheet("""
            QComboBox {
                padding: 16px 20px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QComboBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
            QComboBox::drop-down {
                border: none;
                width: 35px;
            }
            QComboBox::down-arrow {
                image: none;
                border: 6px solid transparent;
                border-top: 10px solid #6c757d;
                margin-right: 8px;
            }
        """)
        self.courseType_comboBox.addItem("共享学分课")
        self.courseType_comboBox.addItem("校内学分课")
        self.formGrid.addWidget(self.courseTypeLabel, 0, 0)
        self.formGrid.addWidget(self.courseType_comboBox, 0, 1)
        
        # Course name
        self.courseNameLabel = QtWidgets.QLabel("选择课程")
        self.courseNameLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.courseName_comboBox = QtWidgets.QComboBox()
        self.courseName_comboBox.setStyleSheet("""
            QComboBox {
                padding: 16px 20px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QComboBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
            QComboBox::drop-down {
                border: none;
                width: 35px;
            }
            QComboBox::down-arrow {
                image: none;
                border: 6px solid transparent;
                border-top: 10px solid #6c757d;
                margin-right: 8px;
            }
        """)
        self.formGrid.addWidget(self.courseNameLabel, 1, 0)
        self.formGrid.addWidget(self.courseName_comboBox, 1, 1)
        
        # Study mode
        self.studyModeLabel = QtWidgets.QLabel("学习模式")
        self.studyModeLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.studyMode_comboBox = QtWidgets.QComboBox()
        self.studyMode_comboBox.setStyleSheet("""
            QComboBox {
                padding: 16px 20px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QComboBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
            QComboBox::drop-down {
                border: none;
                width: 35px;
            }
            QComboBox::down-arrow {
                image: none;
                border: 6px solid transparent;
                border-top: 10px solid #6c757d;
                margin-right: 8px;
            }
        """)
        self.studyMode_comboBox.addItem("从头开始学习")
        self.studyMode_comboBox.addItem("从上次观看视频开始学习")
        self.formGrid.addWidget(self.studyModeLabel, 2, 0)
        self.formGrid.addWidget(self.studyMode_comboBox, 2, 1)
        
        self.taskCardLayout.addLayout(self.formGrid)
        
        # Settings section
        self.settingsSection = QtWidgets.QFrame()
        self.settingsSection.setStyleSheet("""
            QFrame {
                background-color: #f8f9fa;
                border-radius: 15px;
                padding: 25px;
                border: 1px solid #e9ecef;
            }
        """)
        
        self.settingsLayout = QtWidgets.QGridLayout(self.settingsSection)
        self.settingsLayout.setSpacing(25)
        self.settingsLayout.setColumnMinimumWidth(0, 180)
        self.settingsLayout.setColumnMinimumWidth(2, 200)
        self.settingsLayout.setColumnStretch(1, 1)
        self.settingsLayout.setColumnStretch(3, 1)
        
        # Speed setting
        self.speedLabel = QtWidgets.QLabel("播放速度")
        self.speedLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.speed_doubleSpinBox = QtWidgets.QDoubleSpinBox()
        self.speed_doubleSpinBox.setStyleSheet("""
            QDoubleSpinBox {
                padding: 14px 16px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QDoubleSpinBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
        """)
        self.speed_doubleSpinBox.setMinimum(1.0)
        self.speed_doubleSpinBox.setMaximum(20.0)
        self.speed_doubleSpinBox.setValue(1.0)
        self.speed_doubleSpinBox.setSingleStep(0.5)
        self.settingsLayout.addWidget(self.speedLabel, 0, 0)
        self.settingsLayout.addWidget(self.speed_doubleSpinBox, 0, 1)
        
        # Max study time
        self.maxTimeLabel = QtWidgets.QLabel("最大学习时间(分钟)")
        self.maxTimeLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.maxStudyTime_spinBox = QtWidgets.QSpinBox()
        self.maxStudyTime_spinBox.setStyleSheet("""
            QSpinBox {
                padding: 14px 16px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QSpinBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
        """)
        self.maxStudyTime_spinBox.setMaximum(10800)
        self.settingsLayout.addWidget(self.maxTimeLabel, 0, 2)
        self.settingsLayout.addWidget(self.maxStudyTime_spinBox, 0, 3)
        
        # Max video number
        self.maxVideoLabel = QtWidgets.QLabel("最多学习视频数")
        self.maxVideoLabel.setStyleSheet("QLabel { font-size: 16px; font-weight: 600; color: #495057; border: none; background: transparent; }")
        self.maxStudyVideoNum_spinBox = QtWidgets.QSpinBox()
        self.maxStudyVideoNum_spinBox.setStyleSheet("""
            QSpinBox {
                padding: 14px 16px;
                border: 2px solid #e9ecef;
                border-radius: 12px;
                font-size: 16px;
                background-color: white;
                min-height: 25px;
            }
            QSpinBox:focus {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
        """)
        self.settingsLayout.addWidget(self.maxVideoLabel, 1, 0)
        self.settingsLayout.addWidget(self.maxStudyVideoNum_spinBox, 1, 1)
        
        # Checkboxes
        self.violent_checkBox = QtWidgets.QCheckBox("暴力模式")
        self.violent_checkBox.setStyleSheet("""
            QCheckBox {
                font-size: 16px;
                color: #495057;
                font-weight: 500;
            }
            QCheckBox::indicator {
                width: 22px;
                height: 22px;
                border-radius: 4px;
                border: 2px solid #dee2e6;
                background-color: white;
            }
            QCheckBox::indicator:checked {
                background-color: #667eea;
                border-color: #667eea;
            }
            QCheckBox::indicator:hover {
                border-color: #667eea;
            }
        """)
        self.settingsLayout.addWidget(self.violent_checkBox, 1, 2)
        
        self.printLog_checkBox = QtWidgets.QCheckBox("输出详细信息")
        self.printLog_checkBox.setStyleSheet("""
            QCheckBox {
                font-size: 16px;
                color: #495057;
                font-weight: 500;
            }
            QCheckBox::indicator {
                width: 22px;
                height: 22px;
                border-radius: 4px;
                border: 2px solid #dee2e6;
                background-color: white;
            }
            QCheckBox::indicator:checked {
                background-color: #667eea;
                border-color: #667eea;
            }
            QCheckBox::indicator:hover {
                border-color: #667eea;
            }
        """)
        self.printLog_checkBox.setChecked(True)
        self.settingsLayout.addWidget(self.printLog_checkBox, 1, 3)
        
        self.taskCardLayout.addWidget(self.settingsSection)
        
        # Notice section
        self.noticeSection = QtWidgets.QFrame()
        self.noticeSection.setStyleSheet("""
            QFrame {
                background-color: #fff3cd;
                border: 1px solid #ffeaa7;
                border-radius: 8px;
                padding: 15px;
            }
        """)
        
        self.noticeLayout = QtWidgets.QVBoxLayout(self.noticeSection)
        
        self.noticeTitle = QtWidgets.QLabel("⚠️ 注意事项")
        self.noticeTitle.setStyleSheet("""
            QLabel {
                font-size: 20px;
                font-weight: bold;
                color: #856404;
                margin-bottom: 10px;
                border: none;
                background: transparent;
            }
        """)
        self.noticeLayout.addWidget(self.noticeTitle)
        
        self.textBrowser = QtWidgets.QTextBrowser()
        self.textBrowser.setMaximumHeight(160)
        self.textBrowser.setStyleSheet("""
            QTextBrowser {
                border: none;
                background: transparent;
                color: #856404;
                font-size: 18px;
                line-height: 1.7;
                font-weight: 500;
            }
        """)
        self.noticeLayout.addWidget(self.textBrowser)
        
        self.taskCardLayout.addWidget(self.noticeSection)
        
        # Buttons
        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.setSpacing(20)
        
        self.ResetTask_Button = QtWidgets.QPushButton("重置")
        self.ResetTask_Button.setStyleSheet("""
            QPushButton {
                background-color: #6c757d;
                color: white;
                border: none;
                border-radius: 12px;
                padding: 16px 32px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background-color: #5a6268;
            }
            QPushButton:pressed {
                background-color: #495057;
            }
        """)
        self.buttonLayout.addWidget(self.ResetTask_Button)
        
        self.buttonLayout.addStretch()
        
        self.CreateTask_Button = QtWidgets.QPushButton("创建任务")
        self.CreateTask_Button.setStyleSheet("""
            QPushButton {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #667eea, stop: 1 #764ba2);
                color: white;
                border: none;
                border-radius: 12px;
                padding: 16px 32px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #5a67d8, stop: 1 #6b46c1);
            }
            QPushButton:pressed {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #4c51bf, stop: 1 #553c9a);
            }
        """)
        self.buttonLayout.addWidget(self.CreateTask_Button)
        
        self.taskCardLayout.addLayout(self.buttonLayout)
        
        layout.addWidget(self.taskCard)
        layout.addStretch()

    def setupProgressTab(self):
        """设置进度标签页"""
        layout = QtWidgets.QVBoxLayout(self.progressTab)
        layout.setContentsMargins(60, 50, 60, 50)
        layout.setSpacing(30)
        
        # Progress cards container
        self.progressContainer = QtWidgets.QFrame()
        self.progressContainer.setStyleSheet("""
            QFrame {
                background-color: white;
                border-radius: 20px;
                border: 1px solid #e0e0e0;
                box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            }
        """)
        
        self.progressLayout = QtWidgets.QVBoxLayout(self.progressContainer)
        self.progressLayout.setContentsMargins(50, 40, 50, 40)
        self.progressLayout.setSpacing(35)
        
        # Title
        self.progressTitle = QtWidgets.QLabel("学习进度")
        self.progressTitle.setStyleSheet("""
            QLabel {
                font-size: 32px;
                font-weight: bold;
                color: #333;
                margin-bottom: 15px;
                border: none;
                background: transparent;
            }
        """)
        self.progressLayout.addWidget(self.progressTitle)
        
        # Current status
        self.statusCard = QtWidgets.QFrame()
        self.statusCard.setStyleSheet("""
            QFrame {
                background-color: #f8f9fa;
                border-radius: 15px;
                padding: 25px;
                border: 1px solid #e9ecef;
            }
        """)
        
        self.statusLayout = QtWidgets.QHBoxLayout(self.statusCard)
        
        self.statusLabel = QtWidgets.QLabel("当前状态：")
        self.statusLabel.setStyleSheet("""
            QLabel {
                font-size: 18px;
                font-weight: 600;
                color: #495057;
                border: none;
                background: transparent;
            }
        """)
        self.statusLayout.addWidget(self.statusLabel)
        
        self.studing_label = QtWidgets.QLabel("等待中")
        self.studing_label.setStyleSheet("""
            QLabel {
                font-size: 18px;
                color: #667eea;
                font-weight: 600;
                border: none;
                background: transparent;
            }
        """)
        self.statusLayout.addWidget(self.studing_label)
        self.statusLayout.addStretch()
        
        self.progressLayout.addWidget(self.statusCard)
        
        # Progress bars
        self.progressBarsFrame = QtWidgets.QFrame()
        self.progressBarsLayout = QtWidgets.QVBoxLayout(self.progressBarsFrame)
        self.progressBarsLayout.setSpacing(30)
        
        # Course progress
        self.courseProgressFrame = QtWidgets.QFrame()
        self.courseProgressLayout = QtWidgets.QVBoxLayout(self.courseProgressFrame)
        self.courseProgressLayout.setSpacing(12)
        
        self.courseProgressLabel = QtWidgets.QLabel("课程进度")
        self.courseProgressLabel.setStyleSheet("""
            QLabel {
                font-size: 20px;
                font-weight: 600;
                color: #495057;
                border: none;
                background: transparent;
            }
        """)
        self.courseProgressLayout.addWidget(self.courseProgressLabel)
        
        self.course_progressBar = QtWidgets.QProgressBar()
        self.course_progressBar.setStyleSheet("""
            QProgressBar {
                border: none;
                background-color: #e9ecef;
                border-radius: 15px;
                text-align: center;
                font-size: 16px;
                font-weight: 600;
                color: #495057;
                height: 30px;
            }
            QProgressBar::chunk {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #667eea, stop: 1 #764ba2);
                border-radius: 15px;
            }
        """)
        self.courseProgressLayout.addWidget(self.course_progressBar)
        
        self.progressBarsLayout.addWidget(self.courseProgressFrame)
        
        # Video progress
        self.videoProgressFrame = QtWidgets.QFrame()
        self.videoProgressLayout = QtWidgets.QVBoxLayout(self.videoProgressFrame)
        self.videoProgressLayout.setSpacing(12)
        
        self.videoProgressLabel = QtWidgets.QLabel("视频进度")
        self.videoProgressLabel.setStyleSheet("""
            QLabel {
                font-size: 20px;
                font-weight: 600;
                color: #495057;
                border: none;
                background: transparent;
            }
        """)
        self.videoProgressLayout.addWidget(self.videoProgressLabel)
        
        self.video_progressBar = QtWidgets.QProgressBar()
        self.video_progressBar.setStyleSheet("""
            QProgressBar {
                border: none;
                background-color: #e9ecef;
                border-radius: 15px;
                text-align: center;
                font-size: 16px;
                font-weight: 600;
                color: #495057;
                height: 30px;
            }
            QProgressBar::chunk {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #28a745, stop: 1 #20c997);
                border-radius: 15px;
            }
        """)
        self.videoProgressLayout.addWidget(self.video_progressBar)
        
        self.progressBarsLayout.addWidget(self.videoProgressFrame)
        self.progressLayout.addWidget(self.progressBarsFrame)
        
        # Control buttons
        self.controlButtonsLayout = QtWidgets.QHBoxLayout()
        self.controlButtonsLayout.setSpacing(20)
        
        self.ClearLog_Button = QtWidgets.QPushButton("清空日志")
        self.ClearLog_Button.setStyleSheet("""
            QPushButton {
                background-color: #6c757d;
                color: white;
                border: none;
                border-radius: 12px;
                padding: 14px 28px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background-color: #5a6268;
            }
            QPushButton:pressed {
                background-color: #495057;
            }
        """)
        self.controlButtonsLayout.addWidget(self.ClearLog_Button)
        
        self.controlButtonsLayout.addStretch()
        
        self.StopStudy_Button = QtWidgets.QPushButton("停止学习")
        self.StopStudy_Button.setStyleSheet("""
            QPushButton {
                background-color: #dc3545;
                color: white;
                border: none;
                border-radius: 12px;
                padding: 14px 28px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background-color: #c82333;
            }
            QPushButton:pressed {
                background-color: #a71e2a;
            }
        """)
        self.controlButtonsLayout.addWidget(self.StopStudy_Button)
        
        self.progressLayout.addLayout(self.controlButtonsLayout)
        
        # Log section
        self.logSection = QtWidgets.QFrame()
        self.logSection.setStyleSheet("""
            QFrame {
                background-color: #f8f9fa;
                border-radius: 15px;
                padding: 25px;
                border: 1px solid #e9ecef;
            }
        """)
        
        self.logLayout = QtWidgets.QVBoxLayout(self.logSection)
        self.logLayout.setSpacing(15)
        
        self.logTitle = QtWidgets.QLabel("运行日志")
        self.logTitle.setStyleSheet("""
            QLabel {
                font-size: 20px;
                font-weight: 600;
                color: #495057;
                margin-bottom: 10px;
                border: none;
                background: transparent;
            }
        """)
        self.logLayout.addWidget(self.logTitle)
        
        self.study_log = QtWidgets.QTextBrowser()
        self.study_log.setStyleSheet("""
            QTextBrowser {
                background-color: white;
                border: 1px solid #dee2e6;
                border-radius: 12px;
                padding: 15px;
                font-family: 'Consolas', 'Monaco', monospace;
                font-size: 14px;
                color: #495057;
                line-height: 1.5;
            }
        """)
        self.logLayout.addWidget(self.study_log)
        
        self.progressLayout.addWidget(self.logSection)
        
        layout.addWidget(self.progressContainer)

    def setupSettingsTab(self):
        """设置设置标签页"""
        layout = QtWidgets.QVBoxLayout(self.settingsTab)
        layout.setContentsMargins(80, 60, 80, 60)
        layout.setSpacing(30)
        
        # Settings card
        self.settingsCard = QtWidgets.QFrame()
        self.settingsCard.setStyleSheet("""
            QFrame {
                background-color: white;
                border-radius: 20px;
                border: 1px solid #e0e0e0;
                box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            }
        """)
        
        self.settingsCardLayout = QtWidgets.QVBoxLayout(self.settingsCard)
        self.settingsCardLayout.setContentsMargins(60, 50, 60, 50)
        self.settingsCardLayout.setSpacing(40)
        
        # Title
        self.settingsTitle = QtWidgets.QLabel("系统设置")
        self.settingsTitle.setStyleSheet("""
            QLabel {
                font-size: 32px;
                font-weight: bold;
                color: #333;
                margin-bottom: 15px;
                border: none;
                background: transparent;
            }
        """)
        self.settingsCardLayout.addWidget(self.settingsTitle)
        
        # Settings table
        self.setting_table = QtWidgets.QTableWidget()
        self.setting_table.setColumnCount(3)
        self.setting_table.setHorizontalHeaderLabels(["键", "值", "描述"])
        self.setting_table.setStyleSheet("""
            QTableWidget {
                background-color: white;
                border: 1px solid #dee2e6;
                border-radius: 12px;
                gridline-color: #e9ecef;
                font-size: 16px;
                selection-background-color: #e3f2fd;
            }
            QTableWidget::item {
                padding: 12px;
                border-bottom: 1px solid #e9ecef;
            }
            QTableWidget::item:selected {
                background-color: #e3f2fd;
                color: #1976d2;
            }
            QTableWidget::item:hover {
                background-color: #f5f5f5;
            }
            QHeaderView::section {
                background-color: #f8f9fa;
                padding: 15px;
                border: none;
                border-bottom: 2px solid #dee2e6;
                font-weight: 600;
                color: #495057;
                font-size: 16px;
            }
        """)
        
        # Set column widths
        header = self.setting_table.horizontalHeader()
        header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
        header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
        header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
        
        self.settingsCardLayout.addWidget(self.setting_table)
        
        # Settings buttons
        self.settingsButtonsLayout = QtWidgets.QHBoxLayout()
        self.settingsButtonsLayout.setSpacing(20)
        
        self.ResetSetting_Button = QtWidgets.QPushButton("重载设置")
        self.ResetSetting_Button.setStyleSheet("""
            QPushButton {
                background-color: #6c757d;
                color: white;
                border: none;
                border-radius: 12px;
                padding: 16px 32px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background-color: #5a6268;
            }
            QPushButton:pressed {
                background-color: #495057;
            }
        """)
        self.settingsButtonsLayout.addWidget(self.ResetSetting_Button)
        
        self.settingsButtonsLayout.addStretch()
        
        self.SaveSetting_Button = QtWidgets.QPushButton("保存设置")
        self.SaveSetting_Button.setStyleSheet("""
            QPushButton {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #667eea, stop: 1 #764ba2);
                color: white;
                border: none;
                border-radius: 12px;
                padding: 16px 32px;
                font-size: 16px;
                font-weight: 600;
                min-height: 25px;
            }
            QPushButton:hover {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #5a67d8, stop: 1 #6b46c1);
            }
            QPushButton:pressed {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #4c51bf, stop: 1 #553c9a);
            }
        """)
        self.settingsButtonsLayout.addWidget(self.SaveSetting_Button)
        
        self.settingsCardLayout.addLayout(self.settingsButtonsLayout)
        
        layout.addWidget(self.settingsCard)
        layout.addStretch()

    def setupCompatibilityProperties(self):
        """设置兼容性属性，确保现有代码可以正常工作"""
        # 创建旧版本的属性映射
        self.stackedWidget_content = self.navTabWidget
        
        # 页面映射
        self.create_task_page = self.taskTab
        self.task_progress_page = self.progressTab
        self.setting_page = self.settingsTab
        
        # 按钮映射 - 创建虚拟按钮来保持兼容性
        self.TaskPage_Button = QtWidgets.QPushButton()
        self.ProgressPage_Button = QtWidgets.QPushButton()
        self.SettingPage_Button = QtWidgets.QPushButton()
        
        # 连接虚拟按钮到标签页切换
        self.TaskPage_Button.clicked.connect(lambda: self.navTabWidget.setCurrentIndex(0))
        self.ProgressPage_Button.clicked.connect(lambda: self.navTabWidget.setCurrentIndex(1))
        self.SettingPage_Button.clicked.connect(lambda: self.navTabWidget.setCurrentIndex(2))

    def onTabChanged(self, index):
        """标签页切换事件处理"""
        # 这里可以添加标签页切换时的逻辑
        pass

    def setupResponsiveDesign(self, MainGUI):
        """设置响应式设计"""
        # 窗口大小改变时的处理
        def resizeEvent(event):
            self.adjustLayoutForSize(MainGUI.size())
            QtWidgets.QWidget.resizeEvent(MainGUI, event)
        
        # 重写窗口的resizeEvent方法
        MainGUI.resizeEvent = resizeEvent
    
    def adjustLayoutForSize(self, size):
        """根据窗口大小调整布局"""
        width = size.width()
        height = size.height()
        
        # 调整头部用户信息卡片大小
        if width < 1200:
            self.userInfoCard.setFixedSize(220, 60)
            self.userImg_label.setFixedSize(50, 50)
        else:
            self.userInfoCard.setFixedSize(280, 70)
            self.userImg_label.setFixedSize(60, 60)
        
        
        # 调整布局边距
        margin_ratio = min(width / 1500.0, 1.0)
        
        # 调整各页面的边距
        if hasattr(self, 'taskTab'):
            layout = self.taskTab.layout()
            if layout:
                base_margin = int(60 * margin_ratio)
                layout.setContentsMargins(base_margin, base_margin, base_margin, base_margin)
        
        if hasattr(self, 'progressTab'):
            layout = self.progressTab.layout()
            if layout:
                base_margin = int(50 * margin_ratio)
                layout.setContentsMargins(base_margin, base_margin, base_margin, base_margin)
        
        if hasattr(self, 'settingsTab'):
            layout = self.settingsTab.layout()
            if layout:
                base_margin = int(60 * margin_ratio)
                layout.setContentsMargins(base_margin, base_margin, base_margin, base_margin)

    def retranslateUi(self, MainGUI):
        _translate = QtCore.QCoreApplication.translate
        MainGUI.setWindowTitle(_translate("MainGUI", "智慧树刷课脚本 - 现代版"))
        
        # 设置HTML内容
        self.textBrowser.setHtml(_translate("MainGUI", """
            <div style='color: #856404; font-size: 13px; line-height: 1.5;'>
                <p><b>1.</b> 暴力模式不会模拟观看视频，而是直接向服务器发送数据，可能会导致警告或者封号等惩罚，请谨慎使用。</p>
                <p><b>2.</b> 最大学习时间和最多学习视频数设置为0时则为无限。</p>
                <p><b>3.</b> 学习过程中请不要关闭此窗口，否则可能会导致学习进度丢失。</p>
                <p><b>4.</b> 最大学习时间是按视频时间计算，例如一个视频是10分钟，即使使用暴力模式在1分钟内刷完，也按照10分钟计算。</p>
            </div>
        """))
